// 模块引入
import Vue from 'vue'
import App from './App'
import router from './router'
import axios from 'axios'
import store from './store/index'
import infiniteScroll from 'vue-infinite-scroll'
import VueLazyload from 'vue-lazyload'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import {currency} from './util/currency'

// 样式文件引入
import './assets/css/base.css'
import './assets/css/checkout.css'
import './assets/css/login.css'
import './assets/css/product.css'

// UI框架、图片懒加载的使用
Vue.use(ElementUI);
Vue.use(infiniteScroll);
Vue.use(VueLazyload, {
  loading: 'static/loading-svg/loading-bars.svg',
  try: 3
})

// 金额过滤的使用
Vue.filter("currency",currency);
Vue.config.productionTip = false;

// 新建项目Vue实例
new Vue({
  el: '#app',
  store,
  router,
  mounted(){
    this.checkLogin();
    this.getCartCount();
  },
  methods:{
    checkLogin(){ //登陆校验
      axios.get("users/checkLogin").then(res=> {
        let result = res.data;
        if (result.status == "0") {
          this.$store.commit("updateUserInfo", result.result);
        }else{
          this.$store.commit("updateUserInfo", '');
        }
      });
    },
    getCartCount(){ //购物车数量计算
      axios.get("users/getCartCount").then(res=>{
        var result = res.data;
        if(result.status=="0"){
          this.$store.commit("updateCartCount",result.result);
        }
      });
    }
  },
  template: '<App/>',
  components: { App }
});
